//
//  RBPaySucVC.m
//  zhongzhenglu
//
//  Created by XL on 2022/8/11.
//

#import "RBPaySucVC.h"
#import "RBDefine.h"
#import "UIView+RBAdd.h"
#import "UIScrollView+RBAdd.h"
#import <Masonry.h>
#import "RBThemeConfig.h"
#import <UIColor+YYAdd.h>
#import <UIView+YYAdd.h>
#import "RBPager.h"
#import "RanTool.h"
#import "RBNavigationBar.h"
#import "RBCollectionReusableView.h"
#import <UINavigationController+FDFullscreenPopGesture.h>
#import "RBSystemDetailGuessCell.h"
#import "RBMyGroupVC.h"
#import "UINavigationController+RBAdd.h"

@interface RBPaySucVC ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout,UIScrollViewDelegate>

@property(nonatomic, strong)RBNavigationBar *navigationBar;
@property(nonatomic, strong)UILabel *titleL;
@property(nonatomic, strong)UILabel *doneL;

@property(nonatomic, strong)IBOutlet UIView *topView;
@property(nonatomic, strong)IBOutlet UILabel *payStatusL;
@property(nonatomic, strong)IBOutlet UIImageView *payStatusImgView;
@property(nonatomic, strong)IBOutlet UILabel *orderNumL;
@property(nonatomic, strong)IBOutlet UILabel *payTimeL;

@property(nonatomic, strong)UICollectionView *collectionView;
@property(nonatomic, strong)NSMutableArray *dataSource;

@end

@implementation RBPaySucVC

#pragma mark - Lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setup];
    [self fillData];
}

#pragma mark - Private

- (void)setup
{
    self.fd_prefersNavigationBarHidden = YES;
    self.view.backgroundColor = [RBThemeConfig bgGrayColor];
    self.collectionView.hidden = NO;
    self.navigationBar.hidden = NO;
    [self.topView zoomSubViewsWithSelf];
    self.topView.height = Zoom(self.topView.height) + kRBStatusBarHeight + kRBNavigationBarHeight;
    
    self.orderNumL.text = [NSString stringWithFormat:@"订单编号：%@", self.orderNum];
    
}

- (void)fillData
{
    [self.dataSource addObject:({
        RBGroupModel *group = RBGroupModel.new;
        group.headerHeight = self.topView.height;
        group.headerReferenceSize = CGSizeMake(kRBMainScreenWidth, group.headerHeight);
        group.headerView = self.topView;
        group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
        group;
    })];
    [self.dataSource addObject:({
        RBGroupModel *group = RBGroupModel.new;
        group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
        group.sectionInset = UIEdgeInsetsMake(0, Zoom(15), Zoom(15), Zoom(15));
        group.minimumLineSpacing = Zoom(11);
        group.cellModels = ({
            NSMutableArray *arrayM = NSMutableArray.array;
            for (NSInteger i = 0; i < 7; i++)
            {
                [arrayM addObject:({
                    RBCellModel *cellModel = RBCellModel.new;
                    cellModel.reuseCellIdentifier = NSStringFromClass(RBSystemDetailGuessCell.class);
                    cellModel;
                })];
            }
            arrayM;
        });
        group;
    })];
    [self.collectionView reloadData];
}

#pragma mark - Network

#pragma mark - Event

- (void)doneBtnTapped
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)checkOrderBtnTapped:(id)sender
{
    RBMyGroupVC *vc = RBMyGroupVC.new;
    [self.navigationController pushToViewController:vc animated:YES removeVcCount:1];
}

#pragma mark - UICollectionViewDataSource & UICollectionViewDelegate

kRBCollectionViewDataSourceAndDelegateAuto(self.dataSource);

#pragma mark - UIScrollViewDelegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat offsetY = scrollView.contentOffset.y;
    CGFloat distance = Zoom(60);
    if(offsetY > distance)
    {
        self.navigationBar.backgroundAlpha = 1;
        self.titleL.hidden = NO;
        self.doneL.textColor = [RBThemeConfig textBlackColor];
    }
    else
    {
        CGFloat progress = offsetY/distance;
        self.navigationBar.backgroundAlpha = progress;
        self.titleL.hidden = YES;
        if(progress > 0.5)
        {
            self.doneL.textColor = [RBThemeConfig textBlackColor];
        }
        else
        {
            self.doneL.textColor = UIColor.whiteColor;
        }
    }
}

#pragma mark - Setter

#pragma mark - Getter

- (UICollectionView *)collectionView
{
    if (!_collectionView)
    {
        self.collectionView = ({
            UICollectionViewFlowLayout *layout = UICollectionViewFlowLayout.new;
            layout.estimatedItemSize = UICollectionViewFlowLayoutAutomaticSize;
            UICollectionView *view = [UICollectionView.alloc initWithFrame:CGRectZero collectionViewLayout:layout];
            view.showsVerticalScrollIndicator = NO;
            view.showsHorizontalScrollIndicator = NO;
            view.dataSource = self;
            view.delegate = self;
            view.backgroundColor = UIColor.clearColor;
            kRBIgnoreScrollViewInsetsAdjust(view);
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(0);
                make.right.mas_equalTo(0);
                make.bottom.mas_equalTo(0);
                make.top.mas_equalTo(0);
            }];
            view;
        });
    }
    return _collectionView;
}

- (NSMutableArray *)dataSource
{
    if (!_dataSource)
    {
        self.dataSource = ({
            NSMutableArray *arrayM = NSMutableArray.array;
            arrayM;
        });
    }
    return _dataSource;
}

- (RBNavigationBar *)navigationBar
{
    if (!_navigationBar)
    {
        self.navigationBar = ({
            RBNavigationBar *view = RBNavigationBar.new;
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.top.mas_equalTo(0);
                make.height.mas_equalTo(kRBStatusBarHeight + kRBNavigationBarHeight);
            }];
            
            view.needGradientView = NO;
            view.bgColor = UIColor.whiteColor;
            view.backgroundAlpha = 0;
            
            UILabel *titleL = [RanTool labelWithFontSize:17 weight:1 color:[RBThemeConfig textBlackColor] align:0 text:@"支付成功"];
            titleL.hidden = YES;
            self.titleL = titleL;
            [view.naviBar addSubview:titleL];
            [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
                make.center.mas_equalTo(0);
            }];
            
            UILabel *doneL = UILabel.new;
            doneL.text = @"完成";
            doneL.font = [UIFont systemFontOfSize:Zoom(13)];
            doneL.textColor = UIColor.whiteColor;
            self.doneL = doneL;
            [doneL extendResponseArea];
            [doneL rbAddTapGesWithTarget:self action:@selector(doneBtnTapped)];
            [view.naviBar addSubview:doneL];
            [doneL mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.mas_equalTo(0);
                make.right.mas_equalTo(-Zoom(25));
            }];
            
            view;
        });
    }
    return _navigationBar;
}

@end
